//导航菜单
function menuList(opts) {
    this.config = {
        navWrap: '',
        navListWrap: '',
        navListBox: '',
        menuArrs: '',
        type: 'mouseenter',
        renderCallBack: null,
        clickItemCallBack: null
    }
    this.init(opts)
}

menuList.prototype = {
    init: function(opts) {
        this.config = $.extend(this.config, opts || {})
        this.config.navListWrap = `${this.config.navWrap} .g-navList`
        this.config.navListBox = `${this.config.navWrap} .nav-list-box`
        let self = this,
            _config = self.config,
            navListWrap = $(` <div class="g-navList d-ib f-l"></div>`),
            navListBox = $(`<div class='p-a nav-list-box clearfix'></div>`)
        $(_config.navWrap).append(navListWrap)
        $(_config.navWrap).append(navListBox)
        $(_config.navListWrap).each((index, item) => {
            self._renderHTML(item)
            self._bindEnv(item)
        })
    },
    _renderHTML: function(wrap) {
        let self = this,
            _config = self.config
        let ulHtml = $(`<ul class="clearfix"></ul>`)
        $(_config.menuArrs).each((index, item) => {
            let liHtml = $(`<li class="nav-title-box "><a target='_blank' class='nav-title d-b' href=${jumpUrl}/?moduleId=${item.url}&user=${login}>${item.title}</a></li>`)
            $(ulHtml).append(liHtml)
        })
        $(wrap).append($(ulHtml))
    },
    _bindEnv: function(wrap) {
        let self = this,
            _config = self.config
        let navHtml = ``
        $(`${_config.navWrap} .nav-title-box a,${_config.navListBox}`).unbind(_config.type)
        let index = ''
        $(`${_config.navWrap} .nav-title-box a,${_config.navListBox}`).bind(_config.type, function(e) {

            if ($(this).hasClass('nav-title')) {

                index = $(`${_config.navWrap} .nav-title-box a`).index($(this))
            } else {
                index = index
            }
            $(_config.navListBox).html('')
            $(_config.navListBox).css({ 'display': 'block' })
            if (_config.menuArrs[index].items.length > 0) {
                for (var i = 0; i < _config.menuArrs[index].items.length; i++) {
                    let eachList = $(`<div class='f-l eachList'></div>`)
                    let eachListTitle = $(`<a target='_blank' class=' d-b eachListTitle' href=${jumpUrl}/?moduleId=${_config.menuArrs[index].items[i].url}&user=${login}>${_config.menuArrs[index].items[i].title}</a>`)
                    let eachListUL = $(`<ul class='each-list-box'></ul>`)
                    if (_config.menuArrs[index].items[i].items !== undefined && _config.menuArrs[index].items[i].items.length > 0) {
                        for (var j = 0; j < _config.menuArrs[index].items[i].items.length; j++) {
                            let eachListLI = $(`<li><a target='_blank' href=${jumpUrl}/?moduleId=${_config.menuArrs[index].items[i].items[j].url}&user=${login}>${_config.menuArrs[index].items[i].items[j].title}</a></li>`)

                            $(eachListUL).append(eachListLI)
                        }
                    }
                    $(eachList).append(eachListTitle)
                    $(eachList).append(eachListUL)
                    $(_config.navListBox).append(eachList)
                }
            }
        })
        $(`${_config.navListWrap} .clearfix li a,${_config.navListBox}`).bind("mouseleave", function(e) {
            $(_config.navListBox).css({ 'display': 'none' })
        })
    }
}